<?php
class Hostels_model extends Model {

    function Hostels_model()
    {
        // Call the Model constructor
        parent::Model();
    }
    
    function check_hostel_list()
    {
        $this->load->helper('file');
		
		if (!file_exists(BASEPATH . '/public/flatfiles/hostels.php'))
		{
			
			$query = $this->db->get('hostel_locations');
			
			$hostels = '<?php
$hostel_array = array('."\n";
			
			if ($query->num_rows() > 0)
			{
			   $n = 0;
			   foreach ($query->result() as $row)
			   {
				  
				  	$hostels .= "\t$n => array (\n\t\t'id' => '$row->id',\n\t\t'hostel_name' => '$row->hostel_name')"; 
					
					$n++;
					
					if ($n <= count($query->result_array()))
					{
						$hostels .= ",\n";										
					}
					
					
			   }
			}
			
			$hostels .= ');
			?>';
			
			write_file(BASEPATH . '/public/flatfiles/hostels.php', $hostels);
		}

    }
	
	

}
?>